package 国庆编程作业;

import java.util.*;

public class Test04 {
    public static void main(String[] args) {
        Map<Integer,String> map = new HashMap<>();
        map.put(2014,"德国");
        map.put(2010,"西班牙");
        map.put(2006,"意大利");
        map.put(2002,"巴西");
        map.put(1998,"法国");

        /*第一种*/
//        Collection<String> vs = map.values();
//        for (String v : vs){
//            System.out.print(v+"  ");
//        }
//        System.out.println("");
//
//
//        Set<Map.Entry<Integer,String>> entrySet = map.entrySet();
//        for (Map.Entry m : entrySet){
//            System.out.println(m.getKey() + "-" + m.getValue());
//        }

        /*第二种*/
//        Iterator<String> it = map.values().iterator();
//        while (it.hasNext()){
//            System.out.print(it.next()+"  ");
//        }
//

        /*第一种迭代器方式*/
        System.out.println("--------迭代器方式--------");
        Iterator<Integer> keys = map.keySet().iterator();
        while (keys.hasNext()){
            Integer key = keys.next();
            System.out.println(key + "" + map.get(key));
        }

        /*第一种entrySet方式*/
        System.out.println("--------EntrySet遍历--------");
        Set<Map.Entry<Integer,String>> entries = map.entrySet();
        for (Map.Entry<Integer, String> entry : entries) {
            System.out.println(entry.getKey() + "" + entry.getValue());
        }
    }
}
